package com.barbeque.mall.service.wx;

import com.barbeque.mall.bean.brand.MarketBrand;
import com.barbeque.mall.bean.brand.MarketBrandExample;
import com.barbeque.mall.bean.param.CommonData;
import com.barbeque.mall.mapper.MarketBrandMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 苏东宇
 * @since 2022/07/19 22:31
 */
@Transactional
@Service
public class WxBrandServiceImpl implements WxBrandService {

    @Autowired
    MarketBrandMapper marketBrandMapper;

    /**
     * 获取品牌列表
 * @param page
 * @param limit
     * @return com.barbeque.mall.bean.param.CommonData
     * @author 苏东宇
     * @since 2022/07/19 22:32
     */
    @Override
    public CommonData getBrandList(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<MarketBrand> marketBrands = marketBrandMapper.selectByExample(null);

        PageInfo<MarketBrand> marketBrandPageInfo = new PageInfo<>(marketBrands);


        return CommonData.data(marketBrandPageInfo);
    }

    /**
     * 根据id获取品牌详情
 * @param id
     * @return com.barbeque.mall.bean.brand.MarketBrand
     * @author 苏东宇
     * @since 2022/07/19 22:44
     */
    @Override
    public MarketBrand getBrandDetail(Integer id) {

        MarketBrand marketBrand = marketBrandMapper.selectByPrimaryKey(id);

        return marketBrand;
    }

    /**
     * 获取所有的品牌
     * @return java.util.List<com.barbeque.mall.bean.brand.MarketBrand>
     * @author 苏东宇
     * @since 2022/07/21 9:33
     */
    @Override
    public List<MarketBrand> getAllBrandList() {
        MarketBrandExample marketBrandExample = new MarketBrandExample();
        MarketBrandExample.Criteria criteria = marketBrandExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        PageHelper.startPage(1, 3);
        List<MarketBrand> marketBrands = marketBrandMapper.selectByExample(marketBrandExample);
        return marketBrands;
    }

    @Override
    public MarketBrand getBrandById(Integer id) {
        MarketBrand marketBrand = marketBrandMapper.selectByPrimaryKey(id);


        return marketBrand;
    }
}
